package org.fmi.lje.pp.classpath.impl;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.fmi.lje.model.UmlGenProject;
import org.fmi.lje.pp.classpath.ClasspathResolver;

public class UmlGenClasspathResolver implements ClasspathResolver {

	public static Map<UmlGenProject, List<URL>> cache = new HashMap<UmlGenProject, List<URL>>();

	@Override
	public List<URL> getClasspath(UmlGenProject project) {
		List<URL> result;

		if (!cache.containsKey(project)) {
			result = new ArrayList<URL>();

			for (String entry : project.getClassPathEntries().getEntries()) {
				try {
					File fileEntry = new File(project.getProjectFolder() + File.separator + entry);

					result.add(fileEntry.toURI().toURL());
				} catch (MalformedURLException e) {
					log.error(e.getMessage(), e);
				}
			}

			cache.put(project, result);
		} else {
			result = cache.get(project);
		}

		return result;
	}
}
